#include "line.h"

line::line(const point &p_start, const point &p_end):shape(p_start)
{
	m_end = p_end;
}
line::line()
{
	m_end.SetX(0);
	m_end.SetY(0);
}
void line::Draw(HWND hwnd,int xt,int yt)
{
	if(xt<100)
		xt=100;
	else if(xt>700)
		xt=700;
	if(yt>600)
		yt=600;
	SetEnd(point(xt,yt));

	HDC hdc = GetDC(hwnd);

		MoveToEx(hdc,m_pos.GetX(),m_pos.GetY(),NULL);
		LineTo(hdc,m_end.GetX(),m_end.GetY());

	ReleaseDC(hwnd,hdc);
}

void line::Draw(HWND hwnd)
{

	HDC hdc = GetDC(hwnd);

		MoveToEx(hdc,m_pos.GetX(),m_pos.GetY(),NULL);
		LineTo(hdc,m_end.GetX(),m_end.GetY());

	ReleaseDC(hwnd,hdc);
}

void line::Hide(HWND hwnd)
{

	HDC hdc = GetDC(hwnd);
	
		HPEN hPen = CreatePen (PS_SOLID,1,RGB(255,255,255));
		SelectObject (hdc, hPen);
		MoveToEx(hdc,m_pos.GetX(),m_pos.GetY(),NULL);
		LineTo(hdc,m_end.GetX(),m_end.GetY());

	ReleaseDC(hwnd,hdc);
}

bool line::operator==(const line &right) const
{
	if(!(m_pos == right.m_pos))
		return false;
	if(!(m_end == right.m_end))
		return false;

	return true;
}

const line& line::operator =(const line &right)
{
	if(this != &right)
	{
		m_pos = right.m_pos;
		m_end = right.m_end;
	}

	return *this;
}

ostream& operator<<(ostream &output,line l)
{
	output << "start position = " << l.m_pos << "," << "end position = " << l.m_end << endl;

	return output;
}
